package com.manage.utils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 作者：威哥
 * 时间：2021/9/28 16:05
 * 描述：永无bug
 */
public class DateUtils {
    public static Date stringToDate(String date,String pattern){
        //1、创建SimpleDateFormat对象
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        //2、将字符串转换成Date类型
        try {
            return sdf.parse(date);
        } catch (ParseException e) {
            e.printStackTrace();
        }
        return null;
    }

    public static String dateToString(Date date,String pattern){
        //1、创建SimpleDateFormat对象
        SimpleDateFormat sdf = new SimpleDateFormat(pattern);
        //2、将Date类型转换成字符串
        return sdf.format(date);
    }
}
